<template>
  <div class="outDivdes main">
    <scroller lock-x>
      <div style="min-height: 100vh;">
        <div class="mainsss">
          <div class="title">
            <h2>{{ newsDetail.title }}</h2>
            <p>{{ newsDetail.publish_at }}</p>
          </div>
          <div class="content" v-html="newsDetail.content"></div>

        </div>
        <div style="width: 100%; height: 1.5rem;"></div>
      </div>
    </scroller>
  </div>
</template>

<script>
  import api from "../api";
  import {toast} from "../toast";
	export default {
		data() {
			return {
				newsId: null,
        newsDetail: {},
        token: "",
				mobile: "",
			}
		},
		created() {
			let that=this;
			if(that.isTerminal()=='isiOS'){
			    window.webkit.messageHandlers.getToken.postMessage({})
			}else{
			   ZMParentsJsToAndroid.getToken()
      };
      
	  },
		mounted() {
      let that=this;
      window.updateToken = function (token, mobile) {
          that.token = token;
          that.mobile = mobile;
          // 用户已登录
      }
      // that.token = "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhcHAxNzQ1Njg0IiwidXNlcklkIjoiMTc0NTY4NCIsImZyb20iOiJhcHAiLCJuYmYiOjE1NjExODY2MDJ9.Oegm5Gimj50xym2nLAd0CLBFGwg7ZTxtg3dkRkMk7s4sMm4IJQT_qyTCmHfJQdAB8KvaeAh8svFBYqSb1a3Ht2M6NBrRAge-tI8UYh3Px-pue1fH1qS9xCbmqQTaTaLDiSQOl_g-zLyULF7zErIvd3xne65IApb52LhsVQ5gSTo";
      const href = window.location.href;
      this.newsId = href.split('?id=')[1];
      this.getNewsDetail()
		},
		methods: {
			getNewsDetail() {
				api.getSchoolMsg(this.newsId, this.token).then(res => {
					this.newsDetail = res.data;
				}).catch((error) => {
					toast('暂无数据');
				})
			},
      //安卓,IOS方法
      isTerminal(){
        var u = navigator.userAgent;
        var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
        var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        if (isAndroid) {
            return "isAndroid"
        } else if (isiOS) {
            return "isiOS"
        }
      },
		}
	}
</script>

<style lang="scss">
  @import "../styles/mixin.scss";
	.outDivdes {
		width: 100%;
		height: 100vh;
		background: #fff;

		.mainsss {
			padding: 0 0.32rem;
      box-sizing: border-box;
			width: 100%;

			.title {
				margin-top: 0.4rem;
				padding-bottom: 0.34rem;
				border-bottom: 1px solid #E5E8ED;

				h2 {
					margin-bottom: 0.4rem;
					color: #222;
					font-size: 0.4rem;
					font-weight: bold;
					line-height: 0.64rem;
				}

				p {
					color: #BBB;
					font-size: 0.26rem;
					line-height: 0.3rem;
				}
			}

			.content {
				margin-top: 0.32rem;
				width: 100%;

				overflow: hidden;
				p {
					display: block;
					width: 100%;
					height: auto;
					font-size: 0.3rem;

					img {
						display: block;
						width: auto;
						max-width: 6.9rem;
						
						height: auto;
						margin: 0 auto;
						
					}
				}

			}
		}
	}
</style>
